package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-09-24
 * Time: 13:20
 */
class Singleton{
    private static Singleton instance = new Singleton();
    public static Singleton getInstance(){//返回值类型为Singleton
        return instance;
    }
    private Singleton(){
        //静态构造方法让你访问不到
    }

}
public class ThreadDemon28 {
    //“饿汉模式”
    public static void main(String[] args) {
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();
        System.out.println(s1 == s2);//判断s1和s2是否指向的是同一个对象

    }
}
